<?php
header('Content-Type: text/html; charset=utf-8');

include_once("./scripts/class/gmap.class.php");

$scriptname = "NiraPathAPI.php";

$api_query = trim($_GET["q"]);

if  (strlen($api_query) > 0) {
	$gmap = new gmap();
	
	#-> get Distance
	if (preg_match_all('/.*?(<)(>)/is', $api_query, $matches)) {
		$dis_part = explode("<>", $api_query);
		
		echo $gmap->getDis($dis_part[0], $dis_part[1]);
	}
	#-> get Location
	elseif (preg_match_all('/(\\d+)(.)(\\d+)(,)(\\d+)(.)(\\d+)/is', $api_query, $matches)) {
		$loca_split = explode(",", $api_query);
		echo $gmap->getLoca($loca_split[0], $loca_split[1]);
	}
	#-> get Coordinates
	elseif (is_string($api_query) === TRUE) {
		$coords = $gmap->getCoords($api_query);
		
		echo $coords[0].",".$coords[1];
	}
	#-> ERROR
	else {
		echo -1;
	}
}
#-> How To
else {
	echo '
<html>
<head>
<style type="text/css">

a, a:link, a:visited, a:active, a:hover {
	color: #737994;
	text-decoration: none;
}

</style>
	<title>NiraPath - API</title>
</head>
<body style="background-color: #2f1900;">

<div style="text-align: center; font-weight: bold; color: rgb(255, 0, 0);"><span style="font-size: 24pt;"><span style="font-size: 24pt;">NiraPath - API<br />
      <span style="font-size: 12pt;"><span style="color: rgb(50, 205, 50); font-size: 12pt;">Simple to use,</span><br style="color: rgb(50, 205, 50);" />
        <span style="color: rgb(50, 205, 50); font-size: 12pt;">Easy to get,</span><br style="color: rgb(50, 205, 50);" />
        <span style="color: rgb(50, 205, 50); font-size: 12pt;">Visit: Niranda.net</span></span><br />
      </span><span startcont="this"></span></span>
  <div style="text-align: left;">Distance: <a href="?q=Rostock<>Berlin">Live-Test for: .../'.$scriptname.'?q=Rostock<>Berlin</a><br />
    
    <ul style="font-weight: normal;">
      <li style="color: rgb(255, 165, 0);">Calculate the distance between two places, f.e.:</li>
      <ul style="color: rgb(255, 165, 0);">
        <li>Continents</li>
        <li>States</li>
        <li>Cities</li>
        <li>Places</li>
        <li>Streets</li>
        <li>Addresses</li>
      </ul>
      <li style="color: rgb(255, 165, 0);">How to use:</li>
      <ul style="color: rgb(255, 165, 0);">
        <li>.../'.$scriptname.'<span style="font-weight: bold; color: rgb(255, 69, 0);">?q=place1&lt;>place2</span><br />
          </li>
        <li>if you are looking for the distance between "berlin" and "rostock" use this:</li>
        <ul>
          <li>.../'.$scriptname.'?q=berlin&lt;>rostock</li>
        </ul>
        <li>you can also use whitespaces for addresses:</li>
        <ul>
          <li>.../'.$scriptname.'?q=Platz der Freundschaft 1, 18059 Rostock&lt;>Hauptbahnhof Berlin</li>
        </ul>
      </ul>
      <li style="color: rgb(255, 165, 0);">Returns:</li>
      <ul>
        <li style="color: rgb(255, 165, 0);"><span style="font-style: italic;">int</span> in meters</li>
        <li><span style="color: rgb(255, 165, 0);">if sth. is bad, it returns </span><span style="font-style: italic; color: rgb(255, 165, 0);">int -1</span></li>
      </ul>
    </ul>Coordinates: <a href="?q=Berlin">Live-Test for: .../'.$scriptname.'?q=Berlin</a><br />
    
    <ul style="font-weight: normal;">
      <li><span style="color: rgb(255, 215, 0);"><span style="color: rgb(255, 165, 0);">if you are looking for coordinates (latitude and longitude) you have to use this:</span></span></li>
      <ul>
        <li><span style="color: rgb(255, 215, 0);"><span style="color: rgb(255, 165, 0);">.../'.$scriptname.'<span style="font-weight: bold; color: rgb(255, 69, 0);">?q=your place</span></span></span></li>
      </ul>
      <li><span style="color: rgb(255, 165, 0);">you can use this places:</span></li>
      <ul>
        <li><span style="color: rgb(255, 165, 0);">Continents</span></li>
        <li><span style="color: rgb(255, 165, 0);">States</span></li>
        <li><span style="color: rgb(255, 165, 0);">Cities</span></li>
        <li><span style="color: rgb(255, 165, 0);">Places</span></li>
        <li><span style="color: rgb(255, 165, 0);">Streets</span></li>
        <li><span style="color: rgb(255, 165, 0);">Addresses</span></li>
      </ul>
      <li><span style="color: rgb(255, 165, 0);">returns:</span></li>
      <ul>
        <li><span style="color: rgb(255, 165, 0);">latitude;longitude</span></li>
        <li><span style="color: rgb(255, 165, 0);">58.12345;11.54321</span></li>
        <li><span style="color: rgb(255, 165, 0);">"," is the splitter</span></li>
        <li><span style="color: rgb(255, 165, 0);">please note: you have to use the dot "." instead the comma","</span></li>
      </ul>
    </ul>Locations: <a href="?q=54.0769300,12.1267700">Live-Test for: .../'.$scriptname.'?q=54.0769300,12.1267700</a><br />
    
    <ul style="font-weight: normal;">
      <li><span style="color: rgb(255, 165, 0);">you have coordinates and you are looking for the place in the world? Use this:</span></li>
      <ul>
        <li><span style="color: rgb(255, 165, 0);">.../'.$scriptname.'<span style="color: rgb(255, 69, 0); font-weight: bold;">?q=54.12345;11.54321</span></span></li>
      </ul>
      <li><span style="color: rgb(255, 165, 0);">please note:</span></li>
      <ul>
        <li><span style="color: rgb(255, 165, 0);">dot "." for comma ","</span></li>
        <li><span style="color: rgb(255, 165, 0);">"," as splitter</span></li>
        <li><span style="color: rgb(255, 165, 0);">latitude;longitude</span></li>
        <li><span style="color: rgb(255, 165, 0);">f.e.: </span><span style="color: rgb(255, 165, 0);">54.12345,11.54321</span></li>
      </ul>
      <li><span style="color: rgb(255, 165, 0);"><span style="">returns:</span></span></span></li>
      <ul style="color: rgb(255, 165, 0);">
        <li>Platz der Freundschaft 1, 18059 Rostock, Germany</li>
      </ul>
    </ul><span style="font-size: 24pt;"><span style="background-color: rgb(0, 0, 0);"></span></span></div><span style="font-size: 24pt;"><span style="background-color: rgb(0, 0, 0);"></span></span></div>

</body>
</html>
	';
}

?>